import 'dart:collection';

import 'package:dio/dio.dart';
import 'package:xlp_github_app_flutter/common/net/interceptor/response_interceptors.dart';
import 'package:xlp_github_app_flutter/common/net/result_data.dart';

import 'interceptor/header_interceptors.dart';
import 'interceptor/token_interceptor.dart';

class HttpManager {
  static const CONTENT_TYPE_JSON = "application/json";
  static const CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";

  final Dio _dio = Dio(); // 使用默认配置

  final TokenInterceptors _tokenInterceptors = TokenInterceptors();

  HttpManager() {
    _dio.interceptors.add(HeaderInterceptors());

    _dio.interceptors.add(_tokenInterceptors);

    _dio.interceptors.add(ResponseInterceptors());
  }

  Future<ResultData?> netFetch(
      url, params, Map<String, dynamic>? header, Options? option,
      {notip = false}) async {
    Map<String, dynamic> headers = HashMap();
    if (header != null) {
      headers.addAll(header);
    }

    if (option != null) {
      option.headers = headers;
    } else {
      option = Options(method: "get");
      option.headers = headers;
    }
  }
}
